package com.longxi.tianjintianbao.ui.presenter.repair;

import android.content.Intent;

import com.longxi.tianjintianbao.AppConst;
import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.adapter.RepairListPagerAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.base.BasePresenter;
import com.longxi.tianjintianbao.ui.fragment.repair.RepairListFragment;
import com.longxi.tianjintianbao.ui.view.repair.IRepairListAtView;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

public class RepairListAtPresenter extends BasePresenter<IRepairListAtView> {

    private RepairListPagerAdapter repairListPagerAdapter;

    private String buildId = "";
    private String build = "";

    private void initVariable() {
        mCategoryList = new ArrayList<>();
        mCategoryList.add("未派单");
        mCategoryList.add("未接单");
        mCategoryList.add("已接单");
        mCategoryList.add("维修中");
        mCategoryList.add("已完成");
        mCategoryList.add("已回访");
    }

    //tab 标签页
    private List<String> mCategoryList;

    public List<String> getCategoryList() {
        if (mCategoryList == null) {
            mCategoryList = new ArrayList<>();
        }
        return mCategoryList;
    }

    public RepairListAtPresenter(BaseActivity context) {
        super(context);
    }

    public void setBar() {
        Intent intent = mContext.getIntent();
        buildId =intent.getStringExtra(AppConst.BUILDID);
        mContext.setTitle("报事报修");
        mContext.setTvLeft(MyUtils.getString(R.string.home));
        initVariable();
    }

    public void initViewPager(){
        repairListPagerAdapter = new RepairListPagerAdapter(mContext.getSupportFragmentManager(), getCategoryList(), buildId);
        getView().getViewPager().setAdapter(repairListPagerAdapter);
        getView().getViewPager().setOffscreenPageLimit(getCategoryList().size() - 1);
        getView().getTabLayout().setTabSpaceEqual(true);
        getView().getTabLayout().setViewPager(getView().getViewPager());
    }

    public void refreshFragmentUi() {
        RepairListFragment repairListFragment = (RepairListFragment) repairListPagerAdapter.getCurrentFragment();
        repairListFragment.refreshReceiptList();
    }

    @Override
    public void detachView() {
        super.detachView();
        this.repairListPagerAdapter = null;
    }
}
